package com.wash.shoes.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: 正则校验
 * @author: wanxy
 * @date: 2024-12-27 22:08
 **/
public class RegularValidatorUtil {
    private static final String CHINA_PHONE_REGEX = "^1[3-9]\\d{9}$";

    private static final Pattern PATTERN = Pattern.compile(CHINA_PHONE_REGEX);

    /**
     * 校验给定的字符串是否为合法的中国手机号码。
     *
     * @param phoneNumber 要校验的手机号码
     * @return 如果手机号码合法返回true，否则返回false
     */
    public static boolean isValidChinaPhoneNumber(String phoneNumber) {
        if (phoneNumber == null || phoneNumber.length() != 11) {
            return false;
        }
        Matcher matcher = PATTERN.matcher(phoneNumber);
        return matcher.matches();
    }
}
